package com.study.annotationsample;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.study.injectsample.AnnotationUtils;
import com.study.injectsample.OnClick;
import com.study.injectsample.OnLongClick;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //绑定组件,需在setContentView()之后
        AnnotationUtils.bind(this);

    }

    /**
     * 这里实际是执行的OnClickListener的onClick回调
     *
     * @param view
     */
    @OnClick(R.id.btn_button)
    public void onClick(View view) {
        if (view.getId() == R.id.btn_button) {
            Intent intent = new Intent(MainActivity.this, SecondActivity.class);
            intent.putExtra("from", MainActivity.this.getClass().getName());
            startActivity(intent);
        }
    }

    @OnLongClick(R.id.btn_button)
    public boolean onLongClick(View view) {
        Toast.makeText(MainActivity.this, "长按", Toast.LENGTH_LONG).show();
        return false;
    }
}